<template>
  <div class="movie_body">
    <div class="search">
      <div class="search-input iconfont icon-sousuo">
        <input type="text" v-model.lazy.trim="input" @change="getsearchresult"/>
      </div>
    </div>
    <div class="search-result">
      <div class="list-name">
        <b>电影/电视剧/综艺</b>
      </div>
      <div class="list" ref="list">
        <ul>
          <li v-for="item in searchlist" :key="item.id">
            <img :src="item.img" alt="无法显示图片" />
            <div class="info">
              <span>{{ item.moviename }}</span>
              <p>{{ item.ename }}</p>
              <p>{{ item.type }}</p>
              <p>{{ item.date }}</p>
            </div>
            <p>{{ item.grade }}</p>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
import { Toast } from "mint-ui";
export default {
  name:"movie-search",
  data() {
    return {
      searchlist: [],
      input: "",
      //上次进入此页面时的城市数据
      lastcityid:null,
    };
  },
  created() {
    
  },
  activated() {
    window.sessionStorage.setItem('lastpath','/movie/search')
    var nowcityid = this.$store.state.city.id
    //如果城市数据没变,就不重新发送请求获取数据了
    if(this.lastcityid==nowcityid){
      return  
    }
    this.getsearchlist();
    
  },
  methods: {
    //进入页面时获取所有数据
    async getsearchlist() {
      const res = await this.$axios.get("http://192.168.43.145:3000/search");
      console.log("搜索页面发送请求了");
      if (res.status == 200) {
        this.searchlist = res.data;
        this.lastcityid=this.$store.state.city.id
      }else{
        Toast("请求失败");
      }
    },
    //根据搜索内容获取相关数据
    async getsearchresult() {
      const res = await this.$axios.get(
        `http://192.168.43.145:3000/search?moviename_like=${this.input}`
      );
      this.searchlist = res.data;
    },
  },
};
</script>
<style  scoped>
.movie_body{
    overflow: auto;
    flex:1;
    display: flex;
    flex-direction: column;
}
.search-result {
  overflow: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.search .icon-sousuo {
  font-size: 1rem;
}
h4 {
  color: #666;
  font-size: 0.9375rem;
}
h4:active {
  border-bottom: 0.125rem solid red;
  color: rgba(252, 19, 19, 0.973) !important;
}
/* 内容部分-搜索页 */
.search {
  background-color: #f5f5f5;
  height: 2.9375rem;
  display: flex;
  justify-content: center;
  align-items: center;
}
.search-input {
  background-color: white;
  width: 22.0625rem;
  box-sizing: border-box;
  height: 1.875rem;
  border: 0.0625rem solid #e6e6e6;
  border-radius: 0.3125rem;
  padding-left: 0.625rem;
  padding-top: 0.125rem;
}
.search-input input {
  border: 0;
  outline: 0;
  font-size: 0.8125rem;
  height: 1.5rem;
  line-height: 1.5rem;
  width: 95%;
}

/*内容部分-搜索结果*/
.list{
  flex:1;
  overflow: auto;
  position: relative;
  height:100%;
}
.list-name {
  font-size: 0.9375rem;
  color: #999;
  height: 2.4375rem;
  line-height: 2.4375rem;
  border-bottom: 0.0625rem solid #e6e6e6;
  padding-left: 0.9375rem;
}
.list li {
  box-sizing: border-box;
  height: 6.8125rem;
  border-bottom: 0.0625rem dotted #e6e6e6;
  padding: 0.625rem 1rem 0.9375rem 1rem;
}
.list li img {
  width: 3.75rem;
  height: 5.2444rem;
  float: left;
  object-fit: cover;
}
.list li .info {
  float: left;
  margin-left: 0.875rem;
}
.list li .info span {
  font-size: 1.125rem;
  line-height: 1.375rem;
}
.list li .info p {
  font-size: 0.75rem;
  line-height: 1.375rem;
}
.list li > p {
  float: right;
  font-size: 1.0625rem;
  color: #fc7103;
}
</style>
